import React, { useContext } from 'react';
import { ConfigProvider, Switch as AntdSwitch } from 'antd';
import type { SwitchProps as AntdSwitchProps } from 'antd';

import { useSwitchStyles } from './style';
import { switchThemeConfig } from '../../themes/switch';

// 导出样式扩展 Hook，方便用户使用特殊效果
export { useSwitchStyles } from './style';

export interface SwitchProps extends AntdSwitchProps {
  // 继承所有 antd Switch 属性，无需额外属性
}

const Switch: React.FC<SwitchProps> = ({ 
  className,
  ...restProps 
}) => {
  const { styles, cx } = useSwitchStyles();
  const context = useContext(ConfigProvider.ConfigContext);
  
  // 合并样式：基础样式 + 用户样式
  const switchClassName = cx(
    styles.enhancedSwitch,      // 基础样式增强
    className                   // 用户自定义样式
  );

  return (
    <ConfigProvider
      theme={{
        components: {
          Switch: {
            ...switchThemeConfig,
            ...context?.theme?.components?.Switch,
          },
        },
      }}
    >
      <AntdSwitch 
        className={switchClassName} 
        {...restProps} 
      />
    </ConfigProvider>
  );
};

export { Switch };
export default Switch;

